package cj.web.marriage.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriage.domain.PubActivityOrder;

/**
 * 
 * @author 
 *
 */
@DAO
public interface PubActivityOrderDAO{
	
	@SQL("SELECT distinct a.*,b.name as pubActivityName,c.phone as userPhone,d.name,d.sex,DATE_FORMAT(NOW(), '%Y') - SUBSTRING(d.identityCard, 7, 4) AS age FROM PubActivityOrder a left join PubActivity b on a.pubActivityId=b.id left join SCBuyer c on a.userId =c.id and c.deleteflag=1 left join MemberDetail d on c.id =d.userId and d.deleteflag=1 WHERE a.deleteFlag=1 #if(:t.orderNo!=''){ AND a.orderNo like '%##(:t.orderNo)%'} #if(:t.status!=-1){ AND a.status=:t.status } ORDER BY a.updateAt DESC LIMIT :t.start,:t.length ")
    List<PubActivityOrder> query(@SQLParam("t") PubActivityOrder pubActivityOrder);
		
	@SQL("SELECT count(1) FROM PubActivityOrder WHERE deleteFlag=1 #if(:t.orderNo!=''){ AND orderNo like '%##(:t.orderNo)%'} #if(:t.status!=-1){ AND status=:t.status } ")
    int querySize(@SQLParam("t") PubActivityOrder pubActivityOrder);
    
    @SQL("SELECT * FROM PubActivityOrder WHERE id=:1")
    PubActivityOrder queryById(int id);
    
    @SQL("INSERT INTO PubActivityOrder ("
			        		+ "pubActivityId,"
			        		+ "orderNo,"
			        		+ "userId,"
			        		+ "duration,"
			        		+ "price,"
			        		+ "status,"
			        		+ "payWay,"
			        		+ "payOrder,"
			        		+ "source,"
			        		+ "deleteFlag,"
			        		+ "createAt,"
			        		+ "createUser,"
			        		+ "updateAt,"
			        		+ "updateUser"
							+") VALUES ("
							+ ":t.pubActivityId,"
							+ ":t.orderNo,"
							+ ":t.userId,"
							+ ":t.duration,"
							+ ":t.price,"
							+ ":t.status,"
							+ ":t.payWay,"
							+ ":t.payOrder,"
							+ ":t.source,"
							+ "1,"
							+ "now(),"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser"
					+")")
    void create(@SQLParam("t") PubActivityOrder pubActivityOrder);
	
	@SQL("UPDATE PubActivityOrder SET "
	    			        + "pubActivityId=:t.pubActivityId,"
	    			        + "orderNo=:t.orderNo,"
	    			        + "userId=:t.userId,"
	    			        + "duration=:t.duration,"
	    			        + "price=:t.price,"
	    			        + "status=:t.status,"
	    			        + "payWay=:t.payWay,"
	    			        + "payOrder=:t.payOrder,"
	    			        + "source=:t.source,"
	    			        + "updateAt=now(),"
	    			        + "updateUser=:t.updateUser"
    						+ " WHERE id=:t.id")
    void update(@SQLParam("t") PubActivityOrder pubActivityOrder);
    
    @SQL("UPDATE PubActivityOrder SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE PubActivityOrder SET status=:2 WHERE id=:1")
    void updateStatusById(int id,int status);
}